package com.fenger.sys.controller;


import com.fenger.sys.contast.SysConstast;
import com.fenger.sys.domain.LogLogin;
import com.fenger.sys.domain.User;
import com.fenger.sys.service.LogLoginService;
import com.fenger.sys.utils.DataGirdView;
import com.fenger.sys.utils.WebUtils;
import com.fenger.sys.vo.LogLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class LogLoginController {
    private final static String LOGLOGIN_PREFIX = "logLogin/";

    @Autowired
    LogLoginService logLoginService;

    @ResponseBody
    @RequestMapping(LOGLOGIN_PREFIX + "loadAllLogLogin")
    private DataGirdView loadAllLogLogin(LogLoginVo logLoginVo) {
        return this.logLoginService.queryAllLogLogin(logLoginVo);
    }




    @ResponseBody
    @RequestMapping(LOGLOGIN_PREFIX + "deleteLogLogin")
    private DataGirdView deleteLogLogin(LogLoginVo logLoginVo) {

        try {
            this.logLoginService.deleteLogLogin(logLoginVo.getId());
            return new DataGirdView(SysConstast.SUCCESS_CODE, SysConstast.DELETE_SUCCESS_MSG, 1L, null);
        } catch (Exception e) {
            e.printStackTrace();
            return new DataGirdView(SysConstast.ERROR_CODE, SysConstast.DELETE_ERROR_MSG, 0L, null);
        }
    }

    /**
     * 删除多个
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(LOGLOGIN_PREFIX + "deleteListLogLogin")
    private DataGirdView deleteListLogLogin(@RequestParam(value="id[]", required = false) String[] id) {
        List<LogLogin> logLogins = new ArrayList<>();
        for (int i = 0; i < id.length; i++) {
            LogLogin logLogin = new LogLogin();
            logLogin.setId(Integer.valueOf(id[i]));
            logLogins.add(logLogin);
        }
        try {
            this.logLoginService.deleteLogLoginForList(logLogins);
            return new DataGirdView(SysConstast.SUCCESS_CODE, SysConstast.DELETE_SUCCESS_MSG, 0L, null);
        } catch (Exception e) {
            e.printStackTrace();
            return new DataGirdView(SysConstast.ERROR_CODE, SysConstast.DELETE_ERROR_MSG, 0L, null);
        }
    }

}
